package com.atguigu.tingshu.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.atguigu.tingshu.account.AccountFeignClient;
import com.atguigu.tingshu.album.AlbumFeignClient;
import com.atguigu.tingshu.common.constant.RedisConstant;
import com.atguigu.tingshu.common.constant.SystemConstant;
import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.common.rabbit.constant.MqConst;
import com.atguigu.tingshu.common.rabbit.service.RabbitService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.model.order.OrderDerate;
import com.atguigu.tingshu.model.order.OrderDetail;
import com.atguigu.tingshu.model.order.OrderInfo;
import com.atguigu.tingshu.order.helper.SignHelper;
import com.atguigu.tingshu.order.mapper.OrderDerateMapper;
import com.atguigu.tingshu.order.mapper.OrderDetailMapper;
import com.atguigu.tingshu.order.mapper.OrderInfoMapper;
import com.atguigu.tingshu.order.pattern.TradeStrategy;
import com.atguigu.tingshu.order.pattern.factory.TradeStrategyFactory;
import com.atguigu.tingshu.order.service.OrderDetailService;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.atguigu.tingshu.vo.account.AccountDeductVo;
import com.atguigu.tingshu.vo.order.OrderDerateVo;
import com.atguigu.tingshu.vo.order.OrderDetailVo;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import com.atguigu.tingshu.vo.user.UserPaidRecordVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
@SuppressWarnings({"all"})
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Autowired
    private UserFeignClient userFeignClient;

    @Autowired
    private AlbumFeignClient albumFeignClient;

    @Autowired
    private RedisTemplate redisTemplate;

    @Autowired
    private OrderDetailMapper orderDetailMapper;

    @Autowired
    private OrderDetailService orderDetailService;

    @Autowired
    private OrderDerateMapper orderDerateMapper;

    @Autowired
    private RabbitService rabbitService;

    @Autowired
    private AccountFeignClient accountFeignClient;

    @Autowired
    private TradeStrategyFactory tradeStrategyFactory;

    /**
     * 三种商品（VIP会员、专辑、声音）订单结算,渲染订单结算页面
     *
     * @param tradeVo (购买项目类型、购买项目ID、声音数量)
     * @return 订单VO信息
     */
    @Override
    public OrderInfoVo trade(TradeVo tradeVo) {
        TradeStrategy strategy = tradeStrategyFactory.getStrategy(tradeVo.getItemType());
        return strategy.trade(tradeVo);
    }
   /* @Override
    public OrderInfoVo trade(TradeVo tradeVo) {
        //0.创建订单VO对象
        OrderInfoVo orderInfoVo = new OrderInfoVo();
        Long userId = AuthContextHolder.getUserId();
        //1.初始化订单VO中价格、订单明细列表、订单减免明细列表
        //1.1 声明三个初始价格：原价、减免金额、订单金额
        BigDecimal originalAmount = new BigDecimal("0.00");
        BigDecimal orderAmount = new BigDecimal("0.00");
        BigDecimal derateAmount = new BigDecimal("0.00");
        //1.2 声明封装订单明细集合
        List<OrderDetailVo> orderDetailVoList = new ArrayList<>();
        //1.3 声明封装订单减免明细集合
        List<OrderDerateVo> orderDerateVoList = new ArrayList<>();

        //获取购买项目类型 1001-专辑 1002-声音 1003-vip会员
        String itemType = tradeVo.getItemType();
        //TODO 策略模式+工厂模式优化
        //2.处理购买项目类型：VIP套餐
        if (SystemConstant.ORDER_ITEM_TYPE_VIP.equals(itemType)) {
            //2.1 远程调用用户服务，得到购买VIP会员套餐信息
            VipServiceConfig vipServiceConfig = userFeignClient.getVipServiceConfig(tradeVo.getItemId()).getData();
            Assert.notNull(vipServiceConfig, "会员套餐{}不存在", tradeVo.getItemId());
            //2.2 计算商品价格：订单价=原价-减免金额
            originalAmount = vipServiceConfig.getPrice();
            orderAmount = vipServiceConfig.getDiscountPrice();
            if (originalAmount.compareTo(orderAmount) == 1) {
                derateAmount = originalAmount.subtract(orderAmount);
            }
            //2.3 将得到VIP套餐作为订单明细，封装成订单明细VO对象，加入到订单明细列表
            OrderDetailVo orderDetailVo = new OrderDetailVo();
            orderDetailVo.setItemId(vipServiceConfig.getId());
            orderDetailVo.setItemName("会员套餐：" + vipServiceConfig.getName());
            orderDetailVo.setItemUrl(vipServiceConfig.getImageUrl());
            orderDetailVo.setItemPrice(originalAmount);
            orderDetailVoList.add(orderDetailVo);

            //2.4 如有优惠金额，封装订单减免vo对象，加入到订单减免列表
            if (originalAmount.compareTo(orderAmount) == 1) {
                OrderDerateVo orderDerateVo = new OrderDerateVo();
                orderDerateVo.setDerateType(SystemConstant.ORDER_DERATE_VIP_SERVICE_DISCOUNT);
                orderDerateVo.setDerateAmount(derateAmount);
                orderDerateVo.setRemarks("套餐限时减免：" + derateAmount);
                orderDerateVoList.add(orderDerateVo);
            }

        } else if (SystemConstant.ORDER_ITEM_TYPE_ALBUM.equals(itemType)) {
            //3. 处理购买项目类型：专辑
            //3.1 远程调用用户服务，判断用户是否已购买过专辑，如果已买则响应已购买
            Long albumId = tradeVo.getItemId();
            Boolean flag = userFeignClient.isPaidAlbum(albumId).getData();
            if (flag) {
                throw new GuiguException(500, "用户已购买专辑");
            }

            //3.2 远程调用专辑服务，获取专辑价格以及相关折扣(普通、VIP折扣)
            AlbumInfo albumInfo = albumFeignClient.getAlbumInfo(albumId).getData();
            Assert.notNull(albumInfo, "专辑{}不存在", albumId);
            BigDecimal price = albumInfo.getPrice();
            BigDecimal discount = albumInfo.getDiscount();
            BigDecimal vipDiscount = albumInfo.getVipDiscount();

            //3.3 远程调用用户服务，判断当前用户是否是会员
            Boolean isVIP = false;

            UserInfoVo userInfoVo = userFeignClient.getUserInfoVo(userId).getData();
            Assert.notNull(userInfoVo, "用户{}不存在", userId);
            if (userInfoVo.getIsVip().intValue() == 1 && userInfoVo.getVipExpireTime().after(new Date())) {
                isVIP = true;
            }

            //3.4 基于用户角色专辑折扣计算专辑价格(原价、订单价、减免价格)
            originalAmount = price;
            orderAmount = originalAmount;
            if (!isVIP && discount.doubleValue() != -1) {
                //专辑价格 普通用户折扣  订单价格=原价*折扣
                orderAmount =
                        originalAmount.multiply(discount).divide(new BigDecimal("10"), 2, RoundingMode.HALF_UP);
            }
            if (isVIP && vipDiscount.doubleValue() != -1) {
                //专辑价格 VIP会员折扣  订单价格=原价*折扣
                orderAmount =
                        originalAmount.multiply(vipDiscount).divide(new BigDecimal("10"), 2, RoundingMode.HALF_UP);
            }
            //计算专辑价格减免金额 = 原价-订单价格
            derateAmount = originalAmount.subtract(orderAmount);
            //3.5 将专辑信息作为订单明细，封装成订单明细VO对象，加入到订单明细列表
            OrderDetailVo orderDetailVo = new OrderDetailVo();
            orderDetailVo.setItemId(albumId);
            orderDetailVo.setItemName("专辑：" + albumInfo.getAlbumTitle());
            orderDetailVo.setItemUrl(albumInfo.getCoverUrl());
            orderDetailVo.setItemPrice(originalAmount);
            orderDetailVoList.add(orderDetailVo);

            //3.6 如有优惠金额，封装订单减免vo对象，加入到订单减免列表
            if (originalAmount.compareTo(orderAmount) == 1) {
                OrderDerateVo orderDerateVo = new OrderDerateVo();
                orderDerateVo.setDerateType(SystemConstant.ORDER_DERATE_ALBUM_DISCOUNT);
                orderDerateVo.setDerateAmount(derateAmount);
                orderDerateVo.setRemarks("专辑折扣减免：" + derateAmount);
                orderDerateVoList.add(orderDerateVo);
            }
        } else if (SystemConstant.ORDER_ITEM_TYPE_TRACK.equals(itemType)) {
            //4.处理购买项目类型：声音
            //4.1 远程调用专辑服务获取待购买声音列表
            Long trackId = tradeVo.getItemId();
            List<TrackInfo> trackInfoList = albumFeignClient.findWaitBuyTrackInfoList(trackId, tradeVo.getTrackCount()).getData();
            Assert.notNull(trackInfoList, "没有需要结算声音");

            //4.2 远程调用专辑服务获取声音单价-声音不支持折扣
            AlbumInfo albumInfo = albumFeignClient.getAlbumInfo(trackInfoList.get(0).getAlbumId()).getData();
            Assert.notNull(albumInfo, "专辑{}不存在", trackInfoList.get(0).getAlbumId());
            BigDecimal price = albumInfo.getPrice();

            //4.3 封装相关价格
            originalAmount = price.multiply(new BigDecimal(trackInfoList.size()));
            orderAmount = originalAmount;

            //4.4 将待购买声音作为订单明细，封装成订单明细VO对象，加入到订单明细列表
            orderDetailVoList = trackInfoList
                    .stream()
                    .map(trackInfo -> {
                        OrderDetailVo orderDetailVo = new OrderDetailVo();
                        orderDetailVo.setItemId(trackInfo.getId());
                        orderDetailVo.setItemName("声音：" + trackInfo.getTrackTitle());
                        orderDetailVo.setItemUrl(trackInfo.getCoverUrl());
                        orderDetailVo.setItemPrice(price);
                        return orderDetailVo;
                    }).collect(Collectors.toList());

        } else if (SystemConstant.ORDER_ITEM_TYPE_SVIP.equals(itemType)) {
            //处理SVIP业务逻辑
        }

        //5.封装订单VO信息共有的信息，价格赋值、商品明细列表赋值、订单减免明细列表赋值、流水号机制、签名机制
        //5.1 封装第一类信息：三个价格（原价、订单价、减免价）
        orderInfoVo.setOriginalAmount(originalAmount);
        orderInfoVo.setOrderAmount(orderAmount);
        orderInfoVo.setDerateAmount(derateAmount);

        //5.2 封装第二类信息：商品明细列表、优惠列表
        orderInfoVo.setOrderDetailVoList(orderDetailVoList);
        orderInfoVo.setOrderDerateVoList(orderDerateVoList);

        //5.3 封装第三类信息：购买项目类型、流水号机制（本次订单流水号）、签名机制（时间戳+签名值）
        //5.3.1 购买项目类型
        orderInfoVo.setItemType(itemType);
        //5.3.2 流水号机制第一步：生成本次订单流水号，解决回退、重复点击提交造成订单重复提交问题
        //5.3.2.1. 构建当前用户本次订单流水号Key
        String tradeKey = RedisConstant.ORDER_TRADE_NO_PREFIX + userId;
        //5.3.2.2. 构建当前用户本次订单流水号UUID值
        String tradeNo = IdUtil.randomUUID();
        //5.3.2.3. 写入Redis有效时间5分钟
        redisTemplate.opsForValue().set(tradeKey, tradeNo, 5, TimeUnit.MINUTES);
        orderInfoVo.setTradeNo(tradeNo);

        //5.3.3 签名机制
        //5.3.3.1. 生成本次订单时间戳
        long timeMillis = System.currentTimeMillis();
        orderInfoVo.setTimestamp(timeMillis);
        //5.3.3.2 将订单VO转为Map，生成本次订单签名值 TODO 由于付款方式属性payWay为null不需要参与签名
        Map<String, Object> orderInfoMap = BeanUtil.beanToMap(orderInfoVo, false, true);
        String sign = SignHelper.getSign(orderInfoMap);
        //5.3.3.3. 封装Vo中签名值
        orderInfoVo.setSign(sign);
        //6.响应订单vo，客户端完成订单页面渲染
        return orderInfoVo;
    }*/

    /**
     * 提交订单,支持付款方式（微信、余额）
     *
     * @param orderInfoVo 订单vo
     * @return {orderNo:"订单唯一编号"}
     */
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    public Map<String, String> submitOrder(OrderInfoVo orderInfoVo) {
        Long userId = AuthContextHolder.getUserId();
        //1.业务校验1，验证流水号，防止订单重复提交 采用Lua脚本判断删除原子性
        String tradeKey = RedisConstant.ORDER_TRADE_NO_PREFIX + userId;
        //KEYS[1]=流水号Key ARGV[1]=用户提交流水号值
        String script = "if redis.call(\"get\",KEYS[1]) == ARGV[1]\n" +
                "then\n" +
                "    return redis.call(\"del\",KEYS[1])\n" +
                "else\n" +
                "    return 0\n" +
                "end";
        DefaultRedisScript<Boolean> redisScript = new DefaultRedisScript<>(script, Boolean.class);
        Boolean flag = (Boolean) redisTemplate.execute(redisScript, Arrays.asList(tradeKey), orderInfoVo.getTradeNo());
        if (!flag) {
            throw new GuiguException(500, "验证流水号失败");
        }

        //2.业务校验2，验证签名,防止订单确认页中订单数据（商品、金额、数量）被篡改
        //2.1 将参与签名订单VO转为Map，TODO 加签时付款方式属性payWay未参与签名
        Map<String, Object> orderInfoMap = BeanUtil.beanToMap(orderInfoVo);
        //2.2 手动删除掉签名属性payWay
        orderInfoMap.remove("payWay");
        //2.3 验签
        SignHelper.checkSign(orderInfoMap);

        //TODO 后续核心业务处理
        //3. 保存订单，返回订单对象 此时订单支付状态：未支付
        OrderInfo orderInfo = this.saveOrderInfo(orderInfoVo, userId);

        //支付方式：1101-微信 1102-支付宝 1103-账户余额
        String payWay = orderInfoVo.getPayWay();

        //4.TODO 处理付款方式为余额
        if (SystemConstant.ORDER_PAY_ACCOUNT.equals(payWay)) {
            //4.1 远程调用"账户服务"，检查扣减余额
            //4.1.1 构建扣减账户余额VO对象AccountDeductVo
            AccountDeductVo accountDeductVo = new AccountDeductVo();
            accountDeductVo.setOrderNo(orderInfo.getOrderNo());
            accountDeductVo.setUserId(orderInfo.getUserId());
            accountDeductVo.setAmount(orderInfo.getOrderAmount());
            accountDeductVo.setContent(orderInfo.getOrderTitle());

            //4.1.2 远程调用
            Result result = accountFeignClient.checkAndDeduct(accountDeductVo);
            //4.1.3 判断远程调用响应业务状态码，如果不是200抛出异常，触发全局事务回滚
            if (result.getCode().intValue() != 200) {
                //4.2 扣减余额失败，业务终止，回滚全局事务
                throw new GuiguException(result.getCode(), result.getMessage());
            }
            //4.3 扣减余额成功，订单状态改为已支付
            orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_PAID);
            orderInfoMapper.updateById(orderInfo);

            //4.4 远程调用"用户服务"，虚拟物品发货（增加购买记录）
            //4.4.1 构建虚拟物品发货VO对象UserPaidRecordVo
            UserPaidRecordVo userPaidRecordVo = new UserPaidRecordVo();
            userPaidRecordVo.setOrderNo(orderInfo.getOrderNo());
            userPaidRecordVo.setUserId(orderInfo.getUserId());
            userPaidRecordVo.setItemType(orderInfo.getItemType());
            List<OrderDetailVo> orderDetailVoList = orderInfoVo.getOrderDetailVoList();
            if (CollUtil.isNotEmpty(orderDetailVoList)) {
                List<Long> itemIdList = orderDetailVoList
                        .stream()
                        .map(OrderDetailVo::getItemId)
                        .collect(Collectors.toList());
                userPaidRecordVo.setItemIdList(itemIdList);
                //4.4.2 远程调用
                result = userFeignClient.savePaidRecord(userPaidRecordVo);
                if (result.getCode().intValue() != 200) {
                    //4.2 虚拟物品发货失败，业务终止，回滚全局事务
                    throw new GuiguException(result.getCode(), result.getMessage());
                }
            }
        }
        //5.处理付款方式为微信
        if (SystemConstant.ORDER_PAY_WAY_WEIXIN.equals(payWay)) {
            //5.1 发送延迟关单消息，自动关闭超时未支付订单
            int delayTime = 60 * 15;
            rabbitService.sendDelayMessage(MqConst.EXCHANGE_CANCEL_ORDER, MqConst.ROUTING_CANCEL_ORDER, orderInfo.getId(), delayTime);
        }

        //x.封装响应结果 如果是微信支付，根据响应订单编号对接微信支付；如果是余额支付成功，返回订单编号，查询订单详情
        Map<String, String> map = new HashMap<>();
        map.put("orderNo", orderInfo.getOrderNo());
        return map;
    }

    /**
     * 保存订单相关信息(订单、订单明细、优惠明细)
     *
     * @param orderInfoVo
     * @param userId
     * @return
     */
    @Override
    public OrderInfo saveOrderInfo(OrderInfoVo orderInfoVo, Long userId) {
        //1.封装订单对象,保存订单
        OrderInfo orderInfo = BeanUtil.copyProperties(orderInfoVo, OrderInfo.class);
        //1.1 设置用户ID
        orderInfo.setUserId(userId);
        //1.2 设置订单标题
        List<OrderDetailVo> orderDetailVoList = orderInfoVo.getOrderDetailVoList();
        if (CollUtil.isNotEmpty(orderDetailVoList)) {
            OrderDetailVo orderDetailVo = orderDetailVoList.get(0);
            orderInfo.setOrderTitle(orderDetailVo.getItemName());
        }
        //1.3 设置订单编号 确保全局唯一且趋势递增 生成策略=当日+雪花算法
        String orderNo = DateUtil.today().replaceAll("-", "") + IdUtil.getSnowflakeNextId();
        orderInfo.setOrderNo(orderNo);
        //1.4 设置订单状态 订单状态：0901-未支付 0902-已支付 0903-已取消
        orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_UNPAID);
        //1.5 保存订单
        orderInfoMapper.insert(orderInfo);
        Long orderId = orderInfo.getId();

        //2.封装订单明细对象,保存订单明细
        if (CollUtil.isNotEmpty(orderDetailVoList)) {
            List<OrderDetail> orderDetailList = orderDetailVoList
                    .stream()
                    .map(orderDetailVo -> {
                        OrderDetail orderDetail = BeanUtil.copyProperties(orderDetailVo, OrderDetail.class);
                        //将订单明细关联订单ID
                        orderDetail.setOrderId(orderId);
                        return orderDetail;
                    }).collect(Collectors.toList());
            orderDetailService.saveBatch(orderDetailList);
        }
        //3.封装订单优惠对象,保存订单优惠明细
        List<OrderDerateVo> orderDerateVoList = orderInfoVo.getOrderDerateVoList();
        if (CollUtil.isNotEmpty(orderDerateVoList)) {
            orderDerateVoList.stream().forEach(orderDerateVo -> {
                OrderDerate orderDerate = BeanUtil.copyProperties(orderDerateVo, OrderDerate.class);
                orderDerate.setOrderId(orderId);
                orderDerateMapper.insert(orderDerate);
            });
        }
        return orderInfo;
    }

    /**
     * 根据订单编号查询订单信息
     *
     * @param orderNo
     * @return
     */
    @Override
    public OrderInfo getOrderInfo(String orderNo) {
        //1.  根据订单编号查询订单信息
        OrderInfo orderInfo = orderInfoMapper.selectOne(
                new LambdaQueryWrapper<OrderInfo>()
                        .eq(OrderInfo::getOrderNo, orderNo)
        );

        //2. 根据订单ID查询订单明细
        List<OrderDetail> orderDetailList = orderDetailMapper.selectList(
                new LambdaQueryWrapper<OrderDetail>()
                        .eq(OrderDetail::getOrderId, orderInfo.getId())
        );
        orderInfo.setOrderDetailList(orderDetailList);

        //3. 根据订单ID查询订单减免列表
        List<OrderDerate> orderDerates = orderDerateMapper.selectList(
                new LambdaQueryWrapper<OrderDerate>()
                        .eq(OrderDerate::getOrderId, orderInfo.getId())
        );
        orderInfo.setOrderDerateList(orderDerates);
        return orderInfo;
    }

    @Override
    public Page<OrderInfo> getOrderByPage(Long userId, Page<OrderInfo> pageInfo) {
        //1.调用持久层动态SQL查询订单及订单明细
        pageInfo = orderInfoMapper.getOrderByPage(pageInfo, userId);
        return pageInfo;
    }

    /**
     * 取消超时未支付订单
     *
     * @param orderId
     */
    @Override
    public void cancelOrder(Long orderId) {
        //1.根据订单ID查询订单，得到订单状态
        OrderInfo orderInfo = orderInfoMapper.selectById(orderId);
        String orderStatus = orderInfo.getOrderStatus();
        //2.判断订单状态，如果是未支付则关闭
        if (SystemConstant.ORDER_STATUS_UNPAID.equals(orderStatus)) {
            orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_CANCEL);
            orderInfoMapper.updateById(orderInfo);
        }
    }

    /**
     * 用户支付成功后，修改订单状态：已支付
     *
     * @param orderNo
     */
    @Override
    public void orderPaySuccess(String orderNo) {
        //1.根据订单编号查询订单状态
        OrderInfo orderInfo = orderInfoMapper.selectOne(
                new LambdaQueryWrapper<OrderInfo>()
                        .eq(OrderInfo::getOrderNo, orderNo)
        );
        //订单状态：0901-未支付 0902-已支付 0903-已取消
        String orderStatus = orderInfo.getOrderStatus();
        if (SystemConstant.ORDER_STATUS_UNPAID.equals(orderStatus)) {
            //2.如果订单状态是未支付：修改订单状态为已支付
            orderInfo.setOrderStatus(SystemConstant.ORDER_STATUS_PAID);
            orderInfoMapper.updateById(orderInfo);

            //3.远程调用"用户服务"虚拟物品发货
            //3.1 构建虚拟物品发货vo对象
            UserPaidRecordVo userPaidRecordVo = new UserPaidRecordVo();
            userPaidRecordVo.setOrderNo(orderNo);
            userPaidRecordVo.setUserId(orderInfo.getUserId());
            userPaidRecordVo.setItemType(orderInfo.getItemType());
            //查询订单明细得的购买项目ID列表
            List<OrderDetail> orderDetailList = orderDetailService.list(
                    new LambdaQueryWrapper<OrderDetail>().eq(OrderDetail::getOrderId, orderInfo.getId())
                            .select(OrderDetail::getItemId)
            );
            List<Long> itemIdList = orderDetailList.stream().map(OrderDetail::getItemId).collect(Collectors.toList());
            userPaidRecordVo.setItemIdList(itemIdList);
            //3.2 执行远程调用，一定要判断调用业务状态码
            Result result = userFeignClient.savePaidRecord(userPaidRecordVo);
            if (result.getCode().intValue() != 200) {
                throw new GuiguException(result.getCode(), result.getMessage());
            }
        }

    }
}
